//
// Created by francklinson on 2021/10/21 AT 15:19.
//
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <functional>
#include <climits>
#include <string>

using namespace std;

class Solution {
public:
    int maximumDifference(vector<int> &nums) {
        // 记录当前遇见的最小值
        // 如果当前值比该值大  可以更新答案
        int ans = -1;
        int preMin = INT_MAX;
        for (auto &x: nums) {
            if (x > preMin) {
                ans = max(ans, x - preMin);
            }
            preMin = min(preMin, x);
        }
        return ans;
    }
};

int main() {
    vector<int> nums{7, 1, 5, 4};
    Solution solution;
    cout << solution.maximumDifference(nums) << endl;
    return 0;
}

